<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <title>随机取人</title>
    <link rel="stylesheet" href="dist/style/weui.css"/>
    <link rel="stylesheet" href="index.css"/>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js" type="text/javascript"></script>
</head>

<body oncontextmenu=self.event.returnValue=false>

<div class="page">
    <div class="weui-form">
        <div class="weui-form__text-area">
            <h2 class="weui-form__title">请输入要添加的名单列表</h2>
            <div class="weui-form__desc">每行一条元素</div>
        </div>

        <div class="weui-form__control-area">
            <div class="weui-cells__group weui-cells__group_form">
                <div class="weui-cells__title">名单列表输入</div>
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cell ">
                        <div class="weui-cell__bd">
                            <textarea name="namelist" id="jobdecribe" rows=3 cols=40
                                      onfocus="window.activeobj=this;this.clock=setInterval(function(){activeobj.style.height=activeobj.scrollHeight+'px';},200);funTransitionHeight(document.getElementById('jobdecribe'), 250);"
                                      onblur="clearInterval(this.clock);" class="weui-textarea"
                                      placeholder="输入名单列表，每行一条元素。"></textarea>
                        </div>
                    </div>

                </div>
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cell weui-cell_active" id="js_cell">
                        <div class="weui-cell__hd"><label class="weui-label">名称</label></div>
                        <div class="weui-cell__bd weui-flex">
                            <input id="js_input" class="weui-input" name="namename" placeholder="请输入列表名称"
                                   maxlength="16"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="weui-form__opr-area">
            <a class="weui-btn weui-btn_primary" href="javascript:" id="showTooltips">确定</a>
            <a href="javascript:turnback1();" class="weui-btn weui-btn_default">返回</a>
        </div>
    </div>
</div>


<script>
    funTransitionHeight(document.getElementById('jobdecribe'), 250)
    var btn = document.getElementById('showTooltips');
    btn.onclick = function () {
        let namename = document.getElementById('js_input').value;
        let namelist = document.getElementById('jobdecribe').value.replace(/^\s+|\s+$/g, '');
        if (namename.length == 0) {
            weui.alert('请输入列表名称');
            return;
        }
        if (namelist.length == 0) {
            weui.alert('请输入列表内容');
            return;
        }
        var myReg = /[-~/.:]/;
        if (myReg.test(namename)) {
            weui.alert('列表名称不允许包含以下特殊符号:-~/.:');
            return;
        }
        if (myReg.test(namelist)) {
            weui.alert('列表内容不允许包含以下特殊符号:-~/.:');
            return;
        }
        if(namelist.indexOf('\n\n')!=-1){
            weui.alert('列表内容用空行，请检查');
            return;
        }
        var loading = weui.loading('正在上传');
        $.ajax({
            type: "post",
            url: "http://39.101.190.160:8000/filei/",
            dataType: "json",
            data: {
                "namename": document.getElementById('js_input').value,
                "namelist": document.getElementById('jobdecribe').value
            },
            success: function (res) {
                loading.hide();
                window.open("selector.html?id=" + res.id, '_self');
            },
            error: function (res) {
                console.log(res)
            },
            complete: function (res) {
            }
        })
    };
    function turnback1() {
        weui.confirm('确定要放弃添加吗', {
            title: '提示',
            buttons: [{
                label: '取消',
                type: 'default',
                onClick: function(){

                }
            }, {
                label: '确定',
                type: 'primary',
                onClick: function(){
                    window.open('selector.html?'+window.location.href.split('?')[1],'_self');
                }
            }]
        });

    }
    function funTransitionHeight(element, time) { // time, 数值，可缺省
        if (typeof window.getComputedStyle == "undefined") return;

        var height = window.getComputedStyle(element).height;

        element.style.transition = "none";    // 本行2015-05-20新增，mac Safari下，貌似auto也会触发transition, 故要none下~

        element.style.height = "auto";
        var targetHeight = window.getComputedStyle(element).height;
        element.style.height = height;
        element.offsetWidth = element.offsetWidth;
        element.offsetWidth;
        if (time) element.style.transition = "height "+ time +"ms";
        element.style.height = targetHeight;
    }
</script>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript" src="dist/weui.js"></script>
<script Language="JavaScript">
    function click() {
        if (event.button==2||event.button==3) {
            weui.alert('粘贴用Control+V哦')
        }
    }
    //引号中提示可自定义
    document.onmousedown=click
</script>
</body>
</html>
